import React from 'react';
import { Button, message } from 'antd';
import { connect } from 'dva';
import { StateType } from '@/common-typings';
import { mapStateToProps } from '../../utils';

class UpdateResult extends React.PureComponent<StateType> {
  toUpdateHomePage = () => {
    this.props.toUpdateHomePage();
  };

  downLoadFailList = () => {
    const { updateFailUrl } = this.props.risk.updateInquiry;
    if (updateFailUrl) {
      window.location.href = `${updateFailUrl.split('.')[0]}.xls`;
    } else {
      message.warning('无更新失败列表');
    }
  };

  render() {
    return (
      <div className="updateResult">
        <div className="borderLine">
          <div className="resultContent">
            <div className="greenBox" />
            <p className="updateResultTip">更新外部风险结果完成</p>
            <p className="updateResultCount">
              成功查询到{this.props.risk.updateInquiry.updateSuccessCount}条
            </p>
            <div className="updateResultBtns">
              <Button type="primary" onClick={this.toUpdateHomePage}>
                返回更新页
              </Button>
              <Button type="primary" onClick={this.downLoadFailList}>
                下载失败名单
              </Button>
            </div>
          </div>
        </div>
      </div>
    );
  }
}

export default connect(mapStateToProps)(UpdateResult);
